﻿//-----------------------------------------------------------------------
// <copyright file="KnownTypeManager.cs" company="Numbrella foundation">
// Copyright (c) Numbrella foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Numbrella.Interaction
{
	using System;
	using System.Collections.Generic;
	using System.Reflection;

	/// <summary>
	/// Manages known types for WCF <see cref="IProblem"/> service serializer.
	/// When service instance is created, generated serializer adds filled in types to the list of known types.
	/// </summary>
	public static class KnownTypeManager
	{
		/// <summary>
		/// Contains list of types filled in <see cref="KnownTypeManager"/>.
		/// </summary>
		private static List<Type> serializerKnowTypes = new List<Type>();

		/// <summary>
		/// Fills manager with the types.
		/// </summary>
		/// <param name="types">Collection of types to fill in <see cref="KnownTypeManager"/>.</param>
		public static void FillTypes(IEnumerable<Type> types)
		{
			if (types == null)
				throw new ArgumentNullException("types");
			foreach (Type type in types)
				if (type == null)
					throw new ArgumentException("All the given types should be valid.", "types");

			serializerKnowTypes = new List<Type>(types);
		}

		/// <summary>
		/// Fills manager with the types.
		/// </summary>
		/// <param name="types">Collection of types to fill in <see cref="KnownTypeManager"/>.</param>
		public static void FillTypes(params Type[] types)
		{
			FillTypes((IEnumerable<Type>)types);
		}

		/// <summary>
		/// Gets collection that contains types filled in <see cref="KnownTypeManager"/>.
		/// </summary>
		/// <param name="provider">The parameter is not used.</param>
		/// <returns>Сollection that contains types filled in <see cref="KnownTypeManager"/>.</returns>
		private static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
		{
			return serializerKnowTypes;
		}
	}
}
